#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5;
typedef long long LL;
LL a[maxn];
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL t;cin>>t;
  while(t--){
    LL n,m;cin>>n>>m;
    for(LL i=0;i<n+100;i++) a[i]=0;
    for(LL i=1;i<=n;i++) cin>>a[i];
    LL pos=0;
    for(LL i=1;i<=n;i++){
        if(i!=a[i]){
            pos=i;
        }
    }

    double res=1.0;
    for(LL i=1;i<=m;i++){
        LL r;double p;
        cin>>r>>p;
        if(r>=pos){
            res*=(1.0-p);
        }
    }
    if(pos==0){
        printf("%.8f\n",1.0);
        continue;
    }
    printf("%.8f\n",1.0-res);
  }
return 0;
}
